<?php

class xxxxbiConfig extends mosDBTable
{
	var $AppName		= NULL;
	var $AppVersion	= NULL;//in DB
	
	var $absolutePath	= NULL;
	var $liveSite		= NULL;
	
	var $list_limit 	= 0;
	var $directory_items_in_row	= 0;
	
	var $showMenuNotLoggedIn	= 0;

	var $act_language	= NULL;
	var $ini_language	= NULL;
	
	var $imagesFolder	= NULL;
	var $allowableFilesExt = array ('gif','jpg','png');
	var $cmod 			= 0;
	var $dmod 			= 0;
	var $fmod 			= 0;
	var $maxFileSize 	= null;
	var $imgWidth 		= 0;
	var $imgHeight 	= 0;
	var $imgTmbWidth	= 0;
	var $imgTmbHeight	= 0;
	
	var $editorWidth	= NULL;
	var $editorHeight	= 0;
	
	var $templatePath	= NULL;
	var $template		= NULL;
	
	var $GMapKey					= NULL;
	var $GMapGBasePath				= NULL;
	var $GMapCustomBasePath		= NULL;
	var $GMapMainCenterPointLat	= 0;
	var $GMapMainCenterPointLng	= 0;
	var $GMapMainZoom				= 0;
	var $GMapMainWidth				= 0;
	var $GMapMainHeight			= 0;
	
	var $DEBUG = NULL;
	var $LOG = NULL;
	
 	function biConfig() {

		global $database;
		global $biConfig;
		$DB = NULL;
		$query = "SELECT * FROM #__bindex_config";
		$database->setQuery($query);
		$database->loadObject($DB);
				if ($database->getErrorNum())
			echo '<h1>'.$database->stderr().'</h1>';
//debugOut($DB);
		
		$this->AppVersion 	= $DB->app_version;
		$this->list_limit 	= $DB->list_limit;

		$this->directory_items_in_row	= $DB->directory_items_in_row;
		
		$this->showMenuNotLoggedIn	= $DB->show_menu_not_logged_in;

		$this->imagesFolder = $DB->images_folder;
		$this->maxFileSize	= $DB->max_file_size;
		$this->imgWidth		= $DB->img_width;
		$this->imgHeight	= $DB->img_height;
		$this->imgTmbWidth	= $DB->img_tmb_width;
		$this->imgTmbHeight	= $DB->img_tmb_height;
		
		$this->editorWidth	= $DB->editor_width;
		$this->editorHeight	= $DB->editor_height;
		
		$this->template		= $DB->template;
		
		$this->GMapKey		= $DB->gmap_key;
		$this->GMapGBasePath	= $DB->gmap_g_basepath;
		$this->GMapCustomBasePath	= $DB->gmap_custom_basepath;
		$this->GMapMainCenterPointLat	= $DB->gmap_main_centerpoint_lat;
		$this->GMapMainCenterPointLng	= $DB->gmap_main_centerpoint_lng;
		$this->GMapMainZoom				= $DB->gmap_main_zoom;
		$this->GMapMainWidth			= $DB->gmap_main_width;
		$this->GMapMainHeight			= $DB->gmap_main_height;
		
		$this->DEBUG		= $DB->debug;
		$this->LOG			= $DB->log;
		
	}
	
	function getConfigFromRequest ()
	{
		die(hier);
		$this->list_limit 				= intval( mosGetParam( $_POST, 'list_limit', 10 ) );
		$this->directory_items_in_row	= intval( mosGetParam( $_POST, 'directory_items_in_row', 0 ) );

		$this->showMenuNotLoggedIn		= intval( mosGetParam( $_POST, 'show_menu_not_logged_in', 0 ) );

		$images_folder 		= mosGetParam( $_POST, 'images_folder', '');
		$max_file_size 		= intval( mosGetParam( $_POST, 'max_file_size', 0) );
		$img_width			= intval( mosGetParam( $_POST, 'img_width', 0) );
		$img_height			= intval( mosGetParam( $_POST, 'img_height', 0) );
		$img_tmb_width		= intval( mosGetParam( $_POST, 'img_tmb_width', 0) );
		$img_tmb_height		= intval( mosGetParam( $_POST, 'img_tmb_height', 0) );

		$editor_width 		= intval( mosGetParam( $_POST, 'editor_width', '') );
		$editor_height 		= intval( mosGetParam( $_POST, 'editor_height', '') );
		
		$temlate			= mosGetParam( $_POST, 'template', '' );

		$this->GMapKey					= mosGetParam( $_POST, 'gmap_key', 0 );
		$this->GMapGBasePath			= mosGetParam( $_POST, 'gmap_g_basepath', '' );
		$this->GMapCustomBasePath		= mosGetParam( $_POST, 'gmap_custom_basepath', '' );
		$this->GMapMainCenterPointLat	= floatval( mosGetParam( $_POST, 'gmap_main_center_lat', '' ) );
		$this->GMapMainCenterPointLng	= floatval( mosGetParam( $_POST, 'gmap_main_center_lng', '' ) );
		$this->GMapMainZoom				= mosGetParam( $_POST, 'gmap_main_zoom', '' );
		$this->GMapMainWidth			= mosGetParam( $_POST, 'gmap_main_width', '' );
		$this->GMapMainHeight			= mosGetParam( $_POST, 'gmap_main_height', '' );
		
		
		$log 				= intval( mosGetParam( $_POST, 'LOG', 2) );
		$debug				= intval( mosGetParam( $_POST, 'DEBUG', 2) );

		if( $images_folder != '' )	$this->imagesFolder = $images_folder; 
		if( $max_file_size > 0 ) 	$this->maxFileSize = $max_file_size;
		if( $img_width > 0) 		$this->imgWidth = $img_width;
		if( $img_height > 0 ) 		$this->imgHeight = $img_height;
		if( $img_tmb_width > 0) 	$this->imgTmbWidth = $img_tmb_width;
		if( $img_tmb_height > 0 ) 	$this->imgTmbHeight = $img_tmb_height;
		
		if( $editor_width != '' ) 	$this->editorWidth = $editor_width; 
		if( $editor_height != '' )	$this->editorHeight = $editor_height; 

		if( $temlate != '' )		$this->template = $temlate; 

		if( $log < 2 )				$this->LOG = $log; 
		if( $debug < 2 )			$this->DEBUG = $debug; 
	} //function
	
	/**
	 * @return bol - true if stored ok
	 */
	function biConfigStore()
	{
		global $database;
global $DBG;		
		$query = "UPDATE `#__bindex_config`"
				. "\n SET" .
					"\n `list_limit` = '".$this->list_limit."', " .
					"\n `directory_items_in_row` = '".$this->directory_items_in_row."', " .
					"\n `show_menu_not_logged_in` = '".$this->showMenuNotLoggedIn."', " .
					"\n `images_folder` = '".$this->imagesFolder."', " .
					"\n `max_file_size` = '".$this->maxFileSize."', " .
					"\n `img_width` = '".$this->imgWidth."', " .
					"\n `img_height` = '".$this->imgHeight."', " .
					"\n `img_tmb_width` = '".$this->imgTmbWidth."', " .
					"\n `img_tmb_height` = '".$this->imgTmbHeight."', " .
					"\n `editor_width` = '".$this->editorWidth."', " .
					"\n `editor_height` = '".$this->editorHeight."', " .
					"\n `gmap_key` = '".$this->GMapKey."', " .
					"\n `gmap_g_basepath` = '".$this->GMapGBasePath."', " .
					"\n `gmap_custom_basepath` = '".$this->GMapCustomBasePath."', " .
					"\n `gmap_main_centerpoint_lat` = '".$this->GMapMainCenterPointLat."', " .
					"\n `gmap_main_centerpoint_lng` = '".$this->GMapMainCenterPointLng."', " .
					"\n `gmap_main_zoom` = '".$this->GMapMainZoom."', " .
					"\n `gmap_main_width` = '".$this->GMapMainWidth."', " .
					"\n `gmap_main_height` = '".$this->GMapMainHeight."', " .
					"\n `template` = '".$this->template."', " .
					"\n `debug` = '".$this->DEBUG."', " .
					"\n `log` = '".$this->LOG."'";
		$database->setQuery($query);
		$database->query();
$DBG->query($query);
		
		return( $database->getErrorNum() ) ? FALSE : TRUE;
						
	} //function
	
	/**
	 * Returns ONE item id of
	 *       
	 *          option=com_bindex
	 */
	function getMyItemID()
	{
		global $database;
global $DBG;
		
		$ret = NULL;
		$ms = NULL;
		$query = "SELECT `id`, `link`" .
				"\n FROM #__menu";
		$database->setQuery($query);
		$ms = $database->loadObjectList();
		foreach( $ms as $me )
		{
			$p = explode( "?", $me->link );
		//	$l = $p[1];
			$ops = explode( "&",  $p[1] );
			foreach( $ops as $ot )
			{
				$ox = explode( "=", $ot );
				if( (isset($ox[0]) && $ox[0]=='option')
					&& (isset($ox[1]) && $ox[1]=='com_bindex') )
				{
					$ret = $me->id;
				}//if
			}//foreach
		} //foreach
		
		return $ret;
	} //function
	
	function getVarText() {
		$txt = '';
		foreach ($this->_alias as $k=>$v) {
			$txt .= "\$$v = '".addslashes( $this->$k )."';\n";
		}
		return $txt;
	}

	function bindGlobals()
	{
		foreach ($this->_alias as $k=>$v) {
			if(isset($GLOBALS[$v]))
			$this->$k = $GLOBALS[$v];
			else
			$this->$k = "";
		}
	}	
	
		
		/**
	 * @param string $path
	 * @param int $fmode
	 * @param int $dmode
	 */
	function chmodRecursive ( $path, $fmode = null, $dmode = null, $force = false )
	{
		if( !$this->cmod ) {
			return false;
		}
		if( !$force ) {
			$fmode = $this->fmod;
			$dmode = $this->dmod;
		}
		$fmode = $fmode < 600 ? decoct( $fmode ) : $fmode;
		$dmode = $dmode < 600 ? decoct( $dmode ) : $dmode;
		if( !strstr( strtoupper( PHP_OS ), "WIN") && function_exists( "exec") ) {
			$path = escapeshellarg( $path );
			if( $fmode ) {
				$fmode = (int) $fmode;
				@exec( "find {$path} -type f -exec chmod {$fmode} {} \;" );
			}
			if( $dmode ) {
				$dmode = (int) $dmode;
				@exec( "find {$path} -type d -exec chmod {$dmode} {} \;" );
			}
		}
		else {
			mosChmodRecursive( $path, $fmode, $dmode );
		}
	}
	
	function loadJS_Tooltips()
	{
		global $mainframe;
		global $biConfig;
	
		/***********************************************
		* Rich HTML Balloon Tooltip- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
		* This notice MUST stay intact for legal use
		* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
		***********************************************/
		$mainframe->addCustomHeadTag('<link rel="stylesheet" type="text/css" media="all" href="components/com_bindex/includes/js/tooltips/balloontip.css" />');
		$mainframe->addCustomHeadTag('<script type="text/javascript" src="'.$biConfig->liveSite.'/components/com_bindex/includes/js/tooltips/balloontip.js"></script>' );
	} //function
	
	function bi_Load_JS_Lightbox ()
	{
		global $mainframe;
		global $biConfig;
		
		$basepath = $biConfig->liveSite.'/components/com_bindex/includes/js/lightbox/';
		#load JS
		
		$mainframe->addCustomHeadTag('<script type="text/javascript" src="'.$basepath.'js/prototype.js"></script>');
		$mainframe->addCustomHeadTag('<script type="text/javascript" src="'.$basepath.'js/scriptaculous.js?load=effects"></script>');
		$mainframe->addCustomHeadTag('<script type="text/javascript" src="'.$basepath.'js/lightbox.js"></script>');

		$mainframe->addCustomHeadTag('<link rel="stylesheet" href="components/com_bindex/includes/js/lightbox/css/lightbox.css" type="text/css" media="screen" />');
	} //function

}//class

?>